# coding:utf-8
# __auth__ = Felix7157

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# 定义一个浏览器
driver = webdriver.Chrome()


class BasePage():
    def open(self, url):
        driver.get(url)

    def find_element(self, *loc):
        return driver.find_element(*loc)

    def input(self, loc, text):
        return self.find_element(*loc).send_keys(text)

    def click(self, loc):
        return self.find_element(*loc).click()

    def clear(self, loc):
        return self.find_element(*loc).clear()


class SearchPage(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        self.search_input = (By.XPATH, '//*[@id="s_kw_wrap"]/input')
        self.search_button = (By.ID, u'su')

    def input_search_text(self, text):
        self.input(self.search_input, text=text)

    def click_search_button(self):
        self.click(self.search_button)

    def clear_search_text(self):
        self.clear(self.search_input)


# 案例
def test_baidu_search_01():
    driver.get('https://www.baidu.com/')
    SearchPage().input_search_text('NBA')
    SearchPage().click_search_button()
    time.sleep(3)


def test_baidu_search_02():
    driver.get('https://www.baidu.com/')
    SearchPage().input_search_text('NBA')
    SearchPage().click_search_button()
    time.sleep(3)
    SearchPage().clear_search_text()
    SearchPage().input_search_text('淘宝')
    SearchPage().click_search_button()
    time.sleep(3)


def test_baidu_search_03():
    driver.get('https://www.baidu.com/')
    SearchPage().input_search_text('NBA')
    SearchPage().click_search_button()
    time.sleep(3)
    SearchPage().clear_search_text()
    SearchPage().input_search_text('淘宝')
    SearchPage().click_search_button()
    time.sleep(3)
    SearchPage().clear_search_text()
    SearchPage().input_search_text('京东')
    SearchPage().click_search_button()
    time.sleep(3)
